<?php
/**
* The default html input Field.
* The <input> tag is used by user to select information.
* An input field can vary in many ways, depending on the type attribute.
* An input field can be a text field, a checkbox, a password field, a radio button, a button, and more.
* The <input> tag is supported in all major browsers.
* Generate a input, you can use the type and attribute you need
* In HTML the <input> tag has no end tag.
* In XHTML the <input> tag must be properly closed.

Attribute
Value
Description

accept 	STF
MIME_type
Specifies the types of files that can be submitted through a file upload (only for type="file")

align TF
left
right
top
middle
bottom
Deprecated. Use styles instead. Specifies the alignment of an image input (only for type="image")

alt STF
text
Specifies an alternate text for an image input (only for type="image")

checked STF
checked
Specifies that an input element should be preselected when the page loads (for type="checkbox" or type="radio")

disabled STF
disabled
Specifies that an input element should be disabled when the page loads

maxlength STF
number
Specifies the maximum length (in characters) of an input field (for type="text" or type="password")

name STF
name
Specifies a name for an input element

readonly STF
readonly
Specifies that an input field should be read-only (for type="text" or type="password")

size STF
number
Specifies the width of an input field

src STF
URL
Specifies the URL to an image to display as a submit button

type STF
button
checkbox
file
hidden
image
password
radio
reset
submit
text

value STF
value
Specifies the value of an input element

*/
class Input extends element
{
    /**
    * Construct an Input. The $type change final html Element
    * @param $id    the html id attribute, it will set name with passes id too
    * @param $type  specifies the type of an input element, the  default type is text (button, checkbox, file, hidden, image, password, radio, reset, submit, text
    * @param $class the html class attribute (used in css)
    * @param $label the form label attribute
    * @param $size  the size of the input
    */
    public function input($id=NULL, $type = "text", $class="input", $label=NULL, $size = null)
    {
        parent::element('input',$id , $class, $label);
        $this->name = $id;
        $this->type = $type;
        $this->size = $size;
    }

    /**
    * Set the value of this field;
    * @param value the string of value
    */
    public function setValue($value)
    {
        $this->value = $value;
    }

    /**
    * Return the actual value of this field
    */
    public function getValue()
    {
        return $this->value;
    }

    /**
    * Disable the input element
    *
    * @param $disabled true for disabled false for enabled
    */
    public function setDisabled(boolean $disabled = NULL)
    {
        if ($disabled)
        {
            $this->disabled = 'disabled';
        }
        else
        {
            unset($this->disabled);
        }
    }

    /**
    * Enaled the input element if it is disabled.
    *
    * @param $enabled true for enabled false for disabled
    */
    public function setEnabled(boolean $enabled)
    {
        $this->setDisabled(!$enabled);
    }

    public function setReadOnly(boolean $readOnly)
    {
        if ($readOnly)
        {
            $this->readOnly = 'readOnly';
        }
        else
        {
            unset($this->readOnly);
        }
    }
}
?>
